package com.ipzoe.common.captcha;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 验证码
 * 
 * @author Eric
 * @date 2019/12/02
 */
public class CaptchaCode implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 验证码的失效时间
     */
    private LocalDateTime expireTime;

    /**
     * 验证码内容
     */
    private String code;

    public CaptchaCode() {

    }

    /**
     * 构造函数
     *
     * @param expireTimeInSeconds
     *            验证码的有效时间，单位 秒
     */
    protected CaptchaCode(long expireTimeInSeconds) {
        this.expireTime = LocalDateTime.now().plusSeconds(expireTimeInSeconds);
    }

    /**
     * 构造函数
     *
     * @param expireTimeInSeconds
     *            验证码的有效时间，单位 秒
     * @param code
     *            验证码内容
     */
    public CaptchaCode(long expireTimeInSeconds, String code) {
        this.expireTime = LocalDateTime.now().plusSeconds(expireTimeInSeconds);
        this.code = code;
    }

    /**
     * 获取验证码是否已经过期
     * 
     * @return
     */
    public boolean isExpired() {
        return LocalDateTime.now().isAfter(this.expireTime);
    }

    /**
     * 获取验证码的失效日期
     * 
     * @return
     */
    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    /**
     * 设置验证码的失效时间
     * 
     * @param expireTime
     */
    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    /**
     * 获取验证码的内容
     * 
     * @return
     */
    public String getCode() {
        return code;
    }

    /**
     * 设置验证码的内容
     * 
     * @param code
     */
    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "VerificationCode [expireTime=" + expireTime + ", code=" + code + "]";
    }

}
